package auto.app.util;

import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

@Component
public class EmailExcelChange {
    @Value("${spring.file.path}")
    private String path;
    /**
     * Excel存入本地
     *
     * @param fileName 文件名称
     * @param workbook Workbook对象
     * @throws IOException IO异常
     */
    public  Boolean ExcelChange(String fileName, Workbook workbook){
        File toFile = new File(path,fileName);
        try {
            OutputStream os = new FileOutputStream(toFile);
            workbook.write(os);
            os.close();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
